(define (zero) `())


(define (is-zero? n) (null? n) )


(define (successor n)
    (successor-aux n #t)
)


(define (successor-aux n plus) 
    (if plus
        (if (is-zero? n)
            `(1)
            (if (= 15 (car n))
                (cons
                    0
                    (successor-aux (cdr n) #t)
                )
                (cons
                    (+ 1 (car n))
                    (cdr n)
                )
            )
        )
        n
    )
)


(define (predecessor n)
    (if (is-zero? n)
        #f
        (predecessor-aux n #t)
    )
)

(define (predecessor-aux n minus) 
    (if minus
        (if (= 0 (car n))
            (cons 
                15 
                (predecessor-aux (cdr n) #t)
            )
            (if (= 1 (car n))
                (if (is-zero? (cdr n))
                    `()
                    (cons
                        (- (car n) 1)
                        (cdr n)
                    )
                )
                (cons
                    (- (car n) 1)
                    (cdr n)
                )
            )
        )
        n
    )
)


(define (my-multi n1 n2)
    (my-multi-aux (zero) n1 n2)
)


(define (my-multi-aux n n1 n2)
    (if (is-zero? n2) 
        n
        (my-multi-aux (my-add n n1) n1 (predecessor n2))
    )
)


(define (my-add n1 n2)
    (if (is-zero? n2) 
        n1
        (my-add (successor n1) (predecessor n2))
    )
)


(define (my-factorial n) 
    (if (eqv? n (zero))
        (successor (zero))
        (my-multi
            n
            (my-factorial (predecessor n))
        )
    )
)


; (display 
;     (successor (zero))
; )

; (display 
;     (predecessor `(0 0 1))
; )

; (display 
;     (my-add `(15 15 15) `(1 1 1))
; )

; (display 
;     (my-multi `(4) `(4))
; )

(display 
    (my-factorial `(10))
)
